// 通用型api
import request from './request'
import axios from 'axios'

// 文件上传 api 地址
// http://{{host}}/api/v1.0/upload/ossUpload 预上传地址
// https://arbitration-web.oss-cn-hangzhou.aliyuncs.com 上传文件
export const ossUpload = (params) => {
  // return request('get', '/api/v1.0/upload/ossUpload', params)
  return request('get', '/mail/ossUpload', params)
}

export const imgOssUpload = (blobInfo, success, failure) => {
  let formdata = new FormData()
  formdata.set('file', blobInfo.blob())
  return axios.post('/mail/view/imgOssUpload', formdata).then(res => {
    return success(res.data.data.src)
  }).catch(res => {
    return failure('error')
  })
}

export const uploadImg = (file) => {
  let formData = new FormData()
  formData.append('file', file)
  return axios.post('mail/view/imgOssUpload').then(res => {
    if (res.data.code === 0) {
      return Promise.resolve(res.data)
    }
    return Promise.reject(res.data)
  }).catch(err => {
    return Promise.reject(err)
  })
}
